﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using DevExpress.XtraGrid;
using DevExpress.XtraGrid.Views.Grid;
using DevExpress.XtraGrid.Columns;
using DevExpress.XtraGrid.Views.Base;
using DevExpress.XtraEditors.Controls;
using DevExpress.XtraEditors.Repository;
using Model;

namespace TanHungLong
{
    public partial class FrmNhanVien : RmsControl.FrmBase
    {
        #region variant
        private FrmMain main = null;
        private FormStatus formStatus = FormStatus.View;
        private PhongBanReduceBOCollection phongBanBOCollection = null;
        private NhanVienBOCollection nhanVienBOCollection = null;
        private ThayDoiChucVuBOCollection thayDoiChucVuBOCollection = null;
        private ThayDoiLuongBOCollection thayDoiLuongBOCollection = null;
        private KhoanPhuCapBOCollection khoanPhuCapBOCollection = null;

        private ChucVuReduceBOCollection chucVuBOCollection = null;
        private BacLuongReduceBOCollection bacLuongBOCollection = null;
        private PhuCapReduceBOCollection phuCapBOCollection = null;

        private DanhMucBOList quocTichBOList = null;
        private DanhMucBOList danTocBOList = null;
        private DanhMucBOList tonGiaoBOList = null;
        private DanhMucBOList chuyenMonBOList = null;
        private DanhMucBOList trinhDoHocVanBOList = null;
        private DanhMucBOList trinhDoNgoaiNguBOList = null;
        private DanhMucBOList bangCapBOList = null;
        private DanhMucBOList trinhDoTinHocBOList = null;

        private RepositoryItemLookUpEdit repLookUpBacLuongTMP = new RepositoryItemLookUpEdit();

        private string COLUMN_FIRST = "Ten";
        private string COLUMN_SECOND = "DienThoai";

        private string COLUMN_FIRST_THAYDOICV = "PhongBanID";
        private string COLUMN_SECOND_THAYDOICV = "ChucVuID";

        private string COLUMN_FIRST_THAYDOILUONG = "NgachLuongID";
        private string COLUMN_SECOND_THAYDOILUONG = "BacLuongID";

        private string COLUMN_FIRST_PHUCAP = "PhuCapID";
        private string COLUMN_SECOND_PHUCAP = "NgayApDung";

        private LoaiDanhMuc loaiDanhMuc = LoaiDanhMuc.None;
        private FrmDanhMuc frmDanhMuc = null;
        private FormClosedEventHandler frmDanhMucClosed = null;
        #endregion variant

        //=====================================
        #region form
        public FrmNhanVien(FrmMain main)
        {
            InitializeComponent();
            this.KeyPreview = true;

            this.main = main;
            this.main.ShowBgr();
            ShowForm(this.main);

            this.Shown += new EventHandler(FrmNhanVien_Shown);
            this.FormClosing += new FormClosingEventHandler(FrmNhanVien_FormClosing);
            this.KeyDown += new KeyEventHandler(FrmNhanVien_KeyDown);

            this.btnRefresh.Click += new EventHandler(btnRefresh_Click);
            this.btnEdit.Click += new EventHandler(btnEdit_Click);
            this.btnSave.Click += new EventHandler(btnSave_Click);
            this.btnCancel.Click += new EventHandler(btnCancel_Click);
            this.btnClose.Click += new EventHandler(btnClose_Click);

            this.btnPrint.ArrowButtonClick += new EventHandler(btnPrint_ArrowButtonClick);
            this.btnPrint.Click += new EventHandler(btnInNhanVien_Click);
            this.btnInNhanVien.Click += new EventHandler(btnInNhanVien_Click);
            this.btnInPhong.Click += new EventHandler(btnInPhong_Click);
            this.btnInTatCa.Click += new EventHandler(btnInTatCa_Click);
            this.btnDong.Click += new EventHandler(btnDong_Click);

            this.lookUpQuocTichID.ButtonClick += new ButtonPressedEventHandler(lookUp_ButtonClick);
            this.lookUpDanTocID.ButtonClick += new ButtonPressedEventHandler(lookUp_ButtonClick);
            this.lookUpTonGiaoID.ButtonClick += new ButtonPressedEventHandler(lookUp_ButtonClick);
            this.lookUpChuyenMonID.ButtonClick += new ButtonPressedEventHandler(lookUp_ButtonClick);
            this.lookUpTrinhDoHocVanID.ButtonClick += new ButtonPressedEventHandler(lookUp_ButtonClick);
            this.lookUpTrinhDoNgoaiNguID.ButtonClick += new ButtonPressedEventHandler(lookUp_ButtonClick);
            this.lookUpBangCapID.ButtonClick += new ButtonPressedEventHandler(lookUp_ButtonClick);
            this.lookUpTrinhDoTinHocID.ButtonClick += new ButtonPressedEventHandler(lookUp_ButtonClick);
            this.lookUpLoaiHopDongLaoDongID.ButtonClick += new ButtonPressedEventHandler(lookUp_ButtonClick);

            this.dtNgayBatDauLamViec.ButtonClick += new ButtonPressedEventHandler(dt_ButtonClick);
            this.dtNgayKetThucLamViec.ButtonClick += new ButtonPressedEventHandler(dt_ButtonClick);

            this.grdViewNhanVien.ShowingEditor += new CancelEventHandler(grdView_ShowingEditor);
            this.grdViewNhanVien.RowCellStyle += new RowCellStyleEventHandler(grdView_RowCellStyle);
            this.grdViewThayDoiChucVu.ShowingEditor += new CancelEventHandler(grdView_ShowingEditor);
            this.grdViewThayDoiChucVu.RowCellStyle += new RowCellStyleEventHandler(grdView_RowCellStyle);
            this.grdViewThayDoiLuong.ShowingEditor += new CancelEventHandler(grdView_ShowingEditor);
            this.grdViewThayDoiLuong.RowCellStyle += new RowCellStyleEventHandler(grdView_RowCellStyle);
            this.grdViewPhuCap.ShowingEditor += new CancelEventHandler(grdView_ShowingEditor);
            this.grdViewPhuCap.RowCellStyle += new RowCellStyleEventHandler(grdView_RowCellStyle);

            this.grdViewThayDoiLuong.CustomRowCellEditForEditing += new CustomRowCellEditEventHandler(grdViewThayDoiLuong_CustomRowCellEditForEditing);

            SetFormStatus(this.formStatus);
        }

        private void FrmNhanVien_KeyDown(object sender, KeyEventArgs e)
        {
            if (this.btnClose.Visible && ((e.KeyCode == Keys.Q && Control.ModifierKeys == Keys.Control) || (e.KeyCode == Keys.F10)))
                this.Close();
            else
                if (this.btnRefresh.Visible && ((e.KeyCode == Keys.R && Control.ModifierKeys == Keys.Control) || (e.KeyCode == Keys.F5)))
                    RefreshData();
                else
                    if (this.btnSave.Visible && ((e.KeyCode == Keys.S && Control.ModifierKeys == Keys.Control) || (e.KeyCode == Keys.F6)))
                        Save();
                    else
                        if (this.btnPrint.Visible && ((e.KeyCode == Keys.P && Control.ModifierKeys == Keys.Control) || (e.KeyCode == Keys.F7)))
                            InNhanVien();
                        else
                            if (this.btnEdit.Visible && ((e.KeyCode == Keys.E && Control.ModifierKeys == Keys.Control) || (e.KeyCode == Keys.F2)))
                                Edit();
                            else
                                if (this.btnCancel.Visible && ((e.KeyCode == Keys.H && Control.ModifierKeys == Keys.Control) || (e.KeyCode == Keys.F12)))
                                    Cancel();
                                else
                                    if ((e.KeyCode == Keys.F && Control.ModifierKeys == Keys.Control) || (e.KeyCode == Keys.F3))
                                        this.lookUpEditPhongBanID.Focus();
        }

        private void FrmNhanVien_Shown(object sender, EventArgs e)
        {
            this.grdViewNhanVien.Focus();

            this.lookUpEditPhongBanID.Width = 305;

            Utility.InitControl(this.lookUpEditPhongBanID, "PhongBanID", "Ten");
            Utility.InitControl(this.repLookUpPhongBanID, "PhongBanID", "Ten");
            Utility.InitControl(this.repLookUpPhongBanID_ThayDoiChucVu, "PhongBanID", "Ten");
            Utility.InitControl(this.repLookUpChucVuID_ThayDoiChucVu, "ChucVuID", "Ten");

            Utility.InitControl(this.lookUpQuocTichID);
            Utility.InitControl(this.lookUpDanTocID);
            Utility.InitControl(this.lookUpTonGiaoID);
            Utility.InitControl(this.lookUpChuyenMonID);
            Utility.InitControl(this.lookUpTrinhDoHocVanID);
            Utility.InitControl(this.lookUpTrinhDoNgoaiNguID);
            Utility.InitControl(this.lookUpBangCapID);
            Utility.InitControl(this.lookUpTrinhDoTinHocID);

            Utility.InitControl(this.lookUpLoaiHopDongLaoDongID);
            Utility.InitControl(this.lookUpTinhTrangCongViecID);
            Utility.InitControl(this.lookUpPhongBanID_NhanVien, "PhongBanID", "Ten");
            Utility.InitControl(this.lookUpChucVuID_NhanVien, "ChucVuID", "Ten");

            Utility.InitControl(this.lookUpNgachLuongID);
            Utility.InitControl(this.repLookUpNgachLuongID);

            Utility.InitControl(this.lookUpBacLuongID, "BacLuongID", "Ten");
            Utility.InitControl(this.repLookUpBacLuongID, "BacLuongID", "Ten");
            Utility.InitControl(this.repLookUpBacLuongTMP, "BacLuongID", "Ten");

            Utility.InitControl(this.repLookUpPhuCapID, "PhuCapID", "Ten");

            this.lookUpEditPhongBanID.Properties.NullText = "Tất cả";

            RefreshData();
            SetFormStatus(this.formStatus);

            this.lookUpEditPhongBanID.EditValueChanged += new EventHandler(lookUpEditPhongBanID_EditValueChanged);
            this.grdViewNhanVien.FocusedRowChanged += new FocusedRowChangedEventHandler(grdViewNhanVien_FocusedRowChanged);
            this.grdViewNhanVien.RowUpdated += new RowObjectEventHandler(grdViewNhanVien_RowUpdated);
            this.grdViewThayDoiChucVu.CellValueChanged += new CellValueChangedEventHandler(grdViewThayDoiChucVu_CellValueChanged);
            this.grdViewThayDoiLuong.CellValueChanged += new CellValueChangedEventHandler(grdViewThayDoiLuong_CellValueChanged);
            this.grdViewPhuCap.CellValueChanged += new CellValueChangedEventHandler(grdViewPhuCap_CellValueChanged);
        }

        private void FrmNhanVien_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (this.allowCloseForm == false)
                e.Cancel = true;
            else
            {
                this.main.Controls.Remove(this);
                this.main.HideBgr();
                this.Dispose();
            }
        }
        #endregion form

        //=====================================
        #region control
        private void lookUp_ButtonClick(object sender, ButtonPressedEventArgs e)
        {
            if (this.formStatus == FormStatus.Edit)
                if (e.Button.Index > 0)
                {
                    LookUpEdit lookUpEdit = (LookUpEdit)sender;
                    if (e.Button.Index == 1)
                    {
                        this.loaiDanhMuc = LoaiDanhMuc.None;
                        switch (lookUpEdit.Name)
                        {
                            case "lookUpQuocTichID":
                                this.loaiDanhMuc = LoaiDanhMuc.QuocTich;
                                break;
                            case "lookUpDanTocID":
                                this.loaiDanhMuc = LoaiDanhMuc.DanToc;
                                break;
                            case "lookUpTonGiaoID":
                                this.loaiDanhMuc = LoaiDanhMuc.TonGiao;
                                break;
                            case "lookUpChuyenMonID":
                                this.loaiDanhMuc = LoaiDanhMuc.ChuyenMon;
                                break;
                            case "lookUpTrinhDoHocVanID":
                                this.loaiDanhMuc = LoaiDanhMuc.TrinhDoHocVan;
                                break;
                            case "lookUpTrinhDoNgoaiNguID":
                                this.loaiDanhMuc = LoaiDanhMuc.TrinhDoNgoaiNgu;
                                break;
                            case "lookUpBangCapID":
                                this.loaiDanhMuc = LoaiDanhMuc.BangCap;
                                break;
                            case "lookUpTrinhDoTinHocID":
                                this.loaiDanhMuc = LoaiDanhMuc.TrinhDoTinHoc;
                                break;
                            case "lookUpLoaiHopDongLaoDongID":
                                this.loaiDanhMuc = LoaiDanhMuc.LoaiHopDongLaoDong;
                                break;
                        }

                        this.frmDanhMuc = new FrmDanhMuc(this.main, this.loaiDanhMuc);
                        this.frmDanhMucClosed = new FormClosedEventHandler(frmDanhMuc_FormClosed);
                        this.frmDanhMuc.FormClosed += this.frmDanhMucClosed;
                        this.frmDanhMuc.Show();
                    }
                    else
                        if (e.Button.Index == 2)
                            lookUpEdit.EditValue = null;
                }
        }

        private void frmDanhMuc_FormClosed(object sender, FormClosedEventArgs e)
        {
            switch (this.loaiDanhMuc)
            {
                case LoaiDanhMuc.QuocTich:
                    this.quocTichBOList = DanhMucBOList.GetDanhMucBOList(LoaiDanhMuc.QuocTich);
                    Utility.SetData(this.lookUpQuocTichID, quocTichBOList, quocTichBOList.Count);
                    break;
                case LoaiDanhMuc.DanToc:
                    this.danTocBOList = DanhMucBOList.GetDanhMucBOList(LoaiDanhMuc.DanToc);
                    Utility.SetData(this.lookUpDanTocID, danTocBOList, danTocBOList.Count);
                    break;
                case LoaiDanhMuc.TonGiao:
                    this.tonGiaoBOList = DanhMucBOList.GetDanhMucBOList(LoaiDanhMuc.TonGiao);
                    Utility.SetData(this.lookUpTonGiaoID, tonGiaoBOList, tonGiaoBOList.Count);
                    break;
                case LoaiDanhMuc.ChuyenMon:
                    this.chuyenMonBOList = DanhMucBOList.GetDanhMucBOList(LoaiDanhMuc.ChuyenMon);
                    Utility.SetData(this.lookUpChuyenMonID, chuyenMonBOList, chuyenMonBOList.Count);
                    break;
                case LoaiDanhMuc.TrinhDoHocVan:
                    this.trinhDoHocVanBOList = DanhMucBOList.GetDanhMucBOList(LoaiDanhMuc.TrinhDoHocVan);
                    Utility.SetData(this.lookUpTrinhDoHocVanID, trinhDoHocVanBOList, trinhDoHocVanBOList.Count);
                    break;
                case LoaiDanhMuc.TrinhDoNgoaiNgu:
                    this.trinhDoNgoaiNguBOList = DanhMucBOList.GetDanhMucBOList(LoaiDanhMuc.TrinhDoNgoaiNgu);
                    Utility.SetData(this.lookUpTrinhDoNgoaiNguID, trinhDoNgoaiNguBOList, trinhDoNgoaiNguBOList.Count);
                    break;
                case LoaiDanhMuc.BangCap:
                    this.bangCapBOList = DanhMucBOList.GetDanhMucBOList(LoaiDanhMuc.BangCap);
                    Utility.SetData(this.lookUpBangCapID, bangCapBOList, bangCapBOList.Count);
                    break;
                case LoaiDanhMuc.TrinhDoTinHoc:
                    this.trinhDoTinHocBOList = DanhMucBOList.GetDanhMucBOList(LoaiDanhMuc.TrinhDoTinHoc);
                    Utility.SetData(this.lookUpTrinhDoTinHocID, trinhDoTinHocBOList, trinhDoTinHocBOList.Count);
                    break;
                case LoaiDanhMuc.LoaiHopDongLaoDong:
                    DanhMucBOList loaiHopDongLaoDongBOList = DanhMucBOList.GetDanhMucBOList(LoaiDanhMuc.LoaiHopDongLaoDong);
                    Utility.SetData(this.lookUpLoaiHopDongLaoDongID, loaiHopDongLaoDongBOList, loaiHopDongLaoDongBOList.Count);
                    break;
            }

            this.frmDanhMuc.FormClosed -= this.frmDanhMucClosed;
            this.frmDanhMucClosed = null;
            this.frmDanhMuc = null;
        }

        private void dt_ButtonClick(object sender, ButtonPressedEventArgs e)
        {
            if (e.Button.Index == 1)
                ((DateEdit)sender).EditValue = null;
        }

        private void lookUpEditPhongBanID_EditValueChanged(object sender, EventArgs e)
        {
            FilterPhongBan();
        }
        #endregion control

        //=====================================
        #region button
        private void btnInNhanVien_Click(object sender, EventArgs e)
        {
            InNhanVien();
        }

        private void btnInPhong_Click(object sender, EventArgs e)
        {
            InTheoPhong();
        }

        private void btnInTatCa_Click(object sender, EventArgs e)
        {
            InTatCa();
        }

        private void btnDong_Click(object sender, EventArgs e)
        {
            this.contextMenuStrip1.Close();
        }

        private void btnPrint_ArrowButtonClick(object sender, EventArgs e)
        {
            this.contextMenuStrip1.Show(this.pnFooter, new Point(this.btnPrint.Location.X, this.btnPrint.Location.Y - 80));
        }

        private void btnRefresh_Click(object sender, EventArgs e)
        {
            RefreshData();
        }

        private void btnEdit_Click(object sender, EventArgs e)
        {
            Edit();
        }

        private void btnSave_Click(object sender, EventArgs e)
        {
            Save();
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            Cancel();
        }

        private void btnClose_Click(object sender, EventArgs e)
        {
            this.Close();
        }
        #endregion button

        //=====================================
        #region grid
        private void grdViewThayDoiLuong_CustomRowCellEditForEditing(object sender, CustomRowCellEditEventArgs e)
        {
            if (this.formStatus == FormStatus.Edit)
            {
                if (e.Column.FieldName == "BacLuongID")
                {
                    if (this.grdViewThayDoiLuong.GetFocusedRowCellValue("NgachLuongID") == null)
                        this.repLookUpBacLuongTMP.DataSource = null;
                    else
                        this.repLookUpBacLuongTMP.DataSource = this.bacLuongBOCollection.FilterData(StaticUtil.GetInt(this.grdViewThayDoiLuong.GetFocusedRowCellValue("NgachLuongID"), -1));

                    e.RepositoryItem = this.repLookUpBacLuongTMP;
                }
            }
        }

        private void grdViewPhuCap_CellValueChanged(object sender, CellValueChangedEventArgs e)
        {
            if (this.formStatus == FormStatus.Edit)
            {
                string fieldName = e.Column.FieldName;
                if (fieldName == "PhuCapID")
                {
                    int? PhuCapID = StaticUtil.GetRealInt(this.grdViewPhuCap.GetRowCellValue(e.RowHandle, "PhuCapID"));
                    double? SoTien = null;
                    if (PhuCapID != null)
                    {
                        PhuCapReduceBO phuCapBO = this.phuCapBOCollection.GetPhuCapReduceBO(PhuCapID.Value);
                        if (phuCapBO != null)
                            SoTien = phuCapBO.SoTien;
                    }

                    this.grdViewPhuCap.SetRowCellValue(e.RowHandle, "SoTien", SoTien);
                }
            }
        }

        private void grdViewThayDoiLuong_CellValueChanged(object sender, CellValueChangedEventArgs e)
        {
            if (this.formStatus == FormStatus.Edit)
            {
                string fieldName = e.Column.FieldName;
                bool thayDoi = false;
                int? NgachLuongID = null;
                int? BacLuongID = null;
                double? HeSo = null;
                double? LuongCoBan = null;
                double? ThanhTien = null;

                switch (fieldName)
                {
                    case "DELE":
                    case "NgachLuongID":
                    case "ThanhTien":
                    case "NgayApDung":
                        thayDoi = true;
                        break;
                    case "BacLuongID":
                        thayDoi = true;
                        BacLuongID = StaticUtil.GetRealInt(this.grdViewThayDoiLuong.GetRowCellValue(e.RowHandle, "BacLuongID"));
                        if (BacLuongID == null)
                            HeSo = null;
                        else
                        {
                            BacLuongReduceBO bacLuongBO = this.bacLuongBOCollection.GetBacLuongReduceBO(BacLuongID.Value);
                            if (bacLuongBO == null)
                                HeSo = null;
                            else
                                HeSo = bacLuongBO.HeSo;
                        }
                        this.grdViewThayDoiLuong.SetRowCellValue(e.RowHandle, "HeSo", HeSo);
                        break;
                    case "HeSo":
                    case "LuongCoBan":
                        thayDoi = true;
                        HeSo = StaticUtil.GetRealDouble(this.grdViewThayDoiLuong.GetRowCellValue(e.RowHandle, "HeSo"));
                        LuongCoBan = StaticUtil.GetRealDouble(this.grdViewThayDoiLuong.GetRowCellValue(e.RowHandle, "LuongCoBan"));
                        if (HeSo == null || LuongCoBan == null)
                            ThanhTien = null;
                        else
                            ThanhTien = HeSo.Value * LuongCoBan.Value;
                        this.grdViewThayDoiLuong.SetRowCellValue(e.RowHandle, "ThanhTien", ThanhTien);
                        break;
                }

                if (thayDoi)
                {
                    DateTime NgayApDung = DateTime.MinValue;
                    DateTime dt = DateTime.MinValue;

                    int length = this.grdViewThayDoiLuong.RowCount;
                    int index = 0;
                    for (int i = 0; i < length; i++)
                    {
                        index = this.grdViewThayDoiLuong.GetVisibleRowHandle(i);
                        if (StaticUtil.GetBool(this.grdViewThayDoiLuong.GetRowCellValue(index, "DELE")) == false)
                        {
                            dt = StaticUtil.GetDateTime(this.grdViewThayDoiLuong.GetRowCellValue(index, "NgayApDung"), DateTime.MinValue);
                            if (NgayApDung.CompareTo(dt) < 0)
                            {
                                NgayApDung = dt;
                                NgachLuongID = StaticUtil.GetRealInt(this.grdViewThayDoiLuong.GetRowCellValue(index, "NgachLuongID"));
                                BacLuongID = StaticUtil.GetRealInt(this.grdViewThayDoiLuong.GetRowCellValue(index, "BacLuongID"));
                                HeSo = StaticUtil.GetRealDouble(this.grdViewThayDoiLuong.GetRowCellValue(index, "HeSo"));
                                LuongCoBan = StaticUtil.GetRealDouble(this.grdViewThayDoiLuong.GetRowCellValue(index, "LuongCoBan"));
                                ThanhTien = StaticUtil.GetRealDouble(this.grdViewThayDoiLuong.GetRowCellValue(index, "ThanhTien"));
                            }
                        }
                    }

                    this.lookUpNgachLuongID.EditValue = NgachLuongID;
                    this.lookUpBacLuongID.EditValue = BacLuongID;
                    this.dtNgayApDungLuong.EditValue = NgayApDung;
                    this.numHeSoLuong.EditValue = HeSo;
                    this.numLuongCoBan.EditValue = LuongCoBan;
                    this.numThanhTien.EditValue = ThanhTien;
                }
            }
        }

        private void grdViewThayDoiChucVu_CellValueChanged(object sender, CellValueChangedEventArgs e)
        {
            if (this.formStatus == FormStatus.Edit)
            {
                string fieldName = e.Column.FieldName;
                if (fieldName == "DELE" || fieldName == "PhongBanID" || fieldName == "ChucVuID" || fieldName == "NgayApDung")
                {
                    int? PhongBanID = null;
                    int? ChucVuID = null;
                    DateTime NgayApDung = DateTime.MinValue;
                    DateTime dt = DateTime.MinValue;

                    int length = this.grdViewThayDoiChucVu.RowCount;
                    int index = 0;
                    for (int i = 0; i < length; i++)
                    {
                        index = this.grdViewThayDoiChucVu.GetVisibleRowHandle(i);
                        if (StaticUtil.GetBool(this.grdViewThayDoiChucVu.GetRowCellValue(index, "DELE")) == false)
                        {
                            dt = StaticUtil.GetDateTime(this.grdViewThayDoiChucVu.GetRowCellValue(index, "NgayApDung"), DateTime.MinValue);
                            if (NgayApDung.CompareTo(dt) < 0)
                            {
                                NgayApDung = dt;
                                PhongBanID = StaticUtil.GetRealInt(this.grdViewThayDoiChucVu.GetRowCellValue(index, "PhongBanID"));
                                ChucVuID = StaticUtil.GetRealInt(this.grdViewThayDoiChucVu.GetRowCellValue(index, "ChucVuID"));
                            }
                        }
                    }

                    this.lookUpPhongBanID_NhanVien.EditValue = PhongBanID;
                    this.lookUpChucVuID_NhanVien.EditValue = ChucVuID;
                }
            }
        }

        private void grdViewNhanVien_RowUpdated(object sender, RowObjectEventArgs e)
        {
            if (e.RowHandle == int.MinValue + 1)
                if (e.Row != null)
                {
                    NhanVienBO nhanVienBO = (NhanVienBO)e.Row;
                    //thêm mới 1 nhân viên - nếu có phòng ban thì thêm 1 row với phòng ban trong ThayDoiChucVu
                    ((ThayDoiChucVuBOCollection)this.bdSourceThayDoiChucVu.DataSource).AddNewThayDoiChucVuBO(nhanVienBO.NhanVienID.Value);
                }
        }

        private void grdViewNhanVien_FocusedRowChanged(object sender, FocusedRowChangedEventArgs e)
        {
            FilterNhanVien();
        }

        private void grdView_ShowingEditor(object sender, CancelEventArgs e)
        {
            GridView grdView = (GridView)sender;
            bool del = StaticUtil.GetBool(grdView.GetFocusedRowCellValue("DELE"));
            string fieldName = grdView.FocusedColumn.FieldName;

            if (del && fieldName != "DELE")
                e.Cancel = true;
            else
                if (fieldName == "DELE" && grdView.FocusedRowHandle == GridControl.NewItemRowHandle)
                    e.Cancel = true;
        }

        private void grdView_RowCellStyle(object sender, RowCellStyleEventArgs e)
        {
            GridView grdView = (GridView)sender;
            bool del = StaticUtil.GetBool(grdView.GetRowCellValue(e.RowHandle, "DELE"));
            int TinhTrangCongViecID = StaticUtil.GetInt(grdView.GetRowCellValue(e.RowHandle, "TinhTrangCongViecID"), 0);

            if (del)
            {
                e.Appearance.Font = MyStyle.DELETE_FONT;
                e.Appearance.ForeColor = MyStyle.DELETE_COLOR;
            }
            else
                if (TinhTrangCongViecID > 1)
                {
                    Color color = (TinhTrangCongViecID == 2 ? Color.FromArgb(192, 64, 0) : Color.Red);
                    e.Appearance.ForeColor = color;
                }
        }
        #endregion grid

        //=====================================
        #region function
        private void FilterPhongBan()
        {
            int PhongBanID = StaticUtil.GetInt(this.lookUpEditPhongBanID.EditValue, -2);
            if (PhongBanID == -2)
                Session.PhongBanID_NhanVien = -1;
            else
                Session.PhongBanID_NhanVien = PhongBanID;

            string swhere = "";
            if (PhongBanID != -2)
                swhere = "PhongBanID=" + PhongBanID.ToString();

            bool showGroup = (PhongBanID == -2);
            this.colPhongBanID.GroupIndex = (showGroup ? 0 : -1);
            if (this.formStatus == FormStatus.Edit)
            {
                this.colDELE.Width = (showGroup ? 25 + 22 : 25);
                this.colSTT0.Width = 25;
            }
            else
            {
                this.colDELE.Width = 25;
                this.colSTT0.Width = (showGroup ? 25 + 22 : 25);
            }

            this.grdViewNhanVien.ActiveFilterString = swhere;
            this.grdViewNhanVien.CheckLoaded();
            SetSttNhanVien();
            FilterNhanVien();
        }

        private void FilterNhanVien()
        {
            Session.NhanVienID = StaticUtil.GetRealInt(this.grdViewNhanVien.GetFocusedRowCellValue("NhanVienID"));
            string where = "";

            if (Session.NhanVienID == null)
                where = "NhanVienID=" + int.MaxValue;
            else
                where = "NhanVienID=" + Session.NhanVienID.Value.ToString();

            this.btnInNhanVien.Text = "In hồ sơ nhân viên " + this.grdViewNhanVien.GetFocusedRowCellDisplayText("Ho") + " " + this.grdViewNhanVien.GetFocusedRowCellDisplayText("Ten");


            int? PhongBanID = StaticUtil.GetRealInt(this.grdViewNhanVien.GetFocusedRowCellValue("PhongBanID"));
            string tenPhongBan = "";
            if (PhongBanID != null)
            {
                PhongBanReduceBO phongBanBO = this.phongBanBOCollection.GetPhongBanReduceBO(PhongBanID.Value);
                if (phongBanBO != null)
                    tenPhongBan = phongBanBO.Ten;
            }
            this.btnInPhong.Text = "In hồ sơ nhân viên " + tenPhongBan;


            this.grdViewThayDoiChucVu.ActiveFilterString = where;
            this.grdViewThayDoiLuong.ActiveFilterString = where;
            this.grdViewPhuCap.ActiveFilterString = where;

            this.grdViewThayDoiChucVu.CheckLoaded();
            this.grdViewThayDoiLuong.CheckLoaded();
            this.grdViewPhuCap.CheckLoaded();

            SetSttThayDoiChucVu();
            SetSttThayDoiLuong();
            SetSttPhuCap();
        }

        private void RefreshData()
        {
            this.repDT_ThayDoiChucVu.MaxValue = DateTime.Now;
            this.repDtNgay_ThayDoiLuong.MaxValue = DateTime.Now;

            int i = 0;
            int length = 0;

            #region BOList
            this.phongBanBOCollection = PhongBanReduceBOCollection.GetPhongBanReduceBOCollection("", "Ten");
            Utility.SetData(this.repLookUpPhongBanID_ThayDoiChucVu, this.phongBanBOCollection, this.phongBanBOCollection.Count);
            Utility.SetData(this.lookUpPhongBanID_NhanVien, this.phongBanBOCollection, this.phongBanBOCollection.Count);


            PhongBanReduceBOCollection tmpPhongBanBOCollection = this.phongBanBOCollection.Clone();
            PhongBanReduceBO phongBanTatCaBO = PhongBanReduceBOCollection.NewPhongBanReduceBO();
            phongBanTatCaBO.PhongBanID = -2;
            phongBanTatCaBO.Ten = "Tất cả";
            tmpPhongBanBOCollection.Insert(0, phongBanTatCaBO);

            PhongBanReduceBO phongBanNullBO = PhongBanReduceBOCollection.NewPhongBanReduceBO();
            phongBanNullBO.PhongBanID = -1;
            phongBanNullBO.Ten = "Chưa có phòng ban";
            tmpPhongBanBOCollection.Add(phongBanNullBO);

            Utility.SetData(this.lookUpEditPhongBanID, tmpPhongBanBOCollection, tmpPhongBanBOCollection.Count);
            Utility.SetData(this.repLookUpPhongBanID, tmpPhongBanBOCollection, tmpPhongBanBOCollection.Count);
            if (this.lookUpEditPhongBanID.EditValue == null)
                this.lookUpEditPhongBanID.EditValue = -2;


            this.quocTichBOList = DanhMucBOList.GetDanhMucBOList(LoaiDanhMuc.QuocTich);
            Utility.SetData(this.lookUpQuocTichID, quocTichBOList, quocTichBOList.Count);

            this.danTocBOList = DanhMucBOList.GetDanhMucBOList(LoaiDanhMuc.DanToc);
            Utility.SetData(this.lookUpDanTocID, danTocBOList, danTocBOList.Count);

            this.tonGiaoBOList = DanhMucBOList.GetDanhMucBOList(LoaiDanhMuc.TonGiao);
            Utility.SetData(this.lookUpTonGiaoID, tonGiaoBOList, tonGiaoBOList.Count);

            this.chuyenMonBOList = DanhMucBOList.GetDanhMucBOList(LoaiDanhMuc.ChuyenMon);
            Utility.SetData(this.lookUpChuyenMonID, chuyenMonBOList, chuyenMonBOList.Count);

            this.trinhDoHocVanBOList = DanhMucBOList.GetDanhMucBOList(LoaiDanhMuc.TrinhDoHocVan);
            Utility.SetData(this.lookUpTrinhDoHocVanID, trinhDoHocVanBOList, trinhDoHocVanBOList.Count);

            this.trinhDoNgoaiNguBOList = DanhMucBOList.GetDanhMucBOList(LoaiDanhMuc.TrinhDoNgoaiNgu);
            Utility.SetData(this.lookUpTrinhDoNgoaiNguID, trinhDoNgoaiNguBOList, trinhDoNgoaiNguBOList.Count);

            this.bangCapBOList = DanhMucBOList.GetDanhMucBOList(LoaiDanhMuc.BangCap);
            Utility.SetData(this.lookUpBangCapID, bangCapBOList, bangCapBOList.Count);

            this.trinhDoTinHocBOList = DanhMucBOList.GetDanhMucBOList(LoaiDanhMuc.TrinhDoTinHoc);
            Utility.SetData(this.lookUpTrinhDoTinHocID, trinhDoTinHocBOList, trinhDoTinHocBOList.Count);

            DanhMucBOList loaiHopDongLaoDongBOList = DanhMucBOList.GetDanhMucBOList(LoaiDanhMuc.LoaiHopDongLaoDong);
            Utility.SetData(this.lookUpLoaiHopDongLaoDongID, loaiHopDongLaoDongBOList, loaiHopDongLaoDongBOList.Count);

            TinhTrangCongViecBOList tinhTrangCongViecBOList = TinhTrangCongViecBOList.NewTinhTrangCongViecBOList();
            Utility.SetData(this.lookUpTinhTrangCongViecID, tinhTrangCongViecBOList, tinhTrangCongViecBOList.Count);

            this.chucVuBOCollection = ChucVuReduceBOCollection.GetChucVuReduceBOCollection("", "Ten");
            Utility.SetData(this.lookUpChucVuID_NhanVien, this.chucVuBOCollection, this.chucVuBOCollection.Count);
            Utility.SetData(this.repLookUpChucVuID_ThayDoiChucVu, this.chucVuBOCollection, this.chucVuBOCollection.Count);

            NgachLuongBOList ngachLuongBOList = NgachLuongBOList.GetNgachLuongBOList();
            Utility.SetData(this.lookUpNgachLuongID, ngachLuongBOList, ngachLuongBOList.Count);
            Utility.SetData(this.repLookUpNgachLuongID, ngachLuongBOList, ngachLuongBOList.Count);

            this.bacLuongBOCollection = BacLuongReduceBOCollection.GetBacLuongReduceBOCollection();
            Utility.SetData(this.repLookUpBacLuongID, this.bacLuongBOCollection, this.bacLuongBOCollection.Count);
            Utility.SetData(this.lookUpBacLuongID, this.bacLuongBOCollection, this.bacLuongBOCollection.Count);

            this.phuCapBOCollection = PhuCapReduceBOCollection.GetPhuCapReduceBOCollection();
            Utility.SetData(this.repLookUpPhuCapID, this.phuCapBOCollection, this.phuCapBOCollection.Count);
            #endregion BOList

            #region DefaultData
            Session.MacDinh_ChucVu = null;
            length = this.chucVuBOCollection.Count;
            for (i = 0; i < length; i++)
                if (StaticUtil.GetBool(this.chucVuBOCollection[i].MacDinh))
                    Session.MacDinh_ChucVu = this.chucVuBOCollection[i].ChucVuID;
            #endregion DefaultData

            #region Data
            this.nhanVienBOCollection = NhanVienBOCollection.GetNhanVienBOCollection();
            this.bdSource.DataSource = this.nhanVienBOCollection.Clone();

            this.thayDoiChucVuBOCollection = ThayDoiChucVuBOCollection.GetThayDoiChucVuBOCollection("", "NgayApDung", "DESC");
            this.bdSourceThayDoiChucVu.DataSource = this.thayDoiChucVuBOCollection.Clone();

            this.thayDoiLuongBOCollection = ThayDoiLuongBOCollection.GetThayDoiLuongBOCollection("", "NgayApDung", "DESC");
            this.bdSourceThayDoiLuong.DataSource = this.thayDoiLuongBOCollection.Clone();

            this.khoanPhuCapBOCollection = KhoanPhuCapBOCollection.GetKhoanPhuCapBOCollection("", "NgayApDung", "DESC");
            this.bdSourcePhuCap.DataSource = this.khoanPhuCapBOCollection.Clone();
            #endregion Data

            FilterPhongBan();
        }

        private void Edit()
        {
            this.formStatus = FormStatus.Edit;
            SetFormStatus(this.formStatus);
            Session.CloseIndex++;
        }

        private void Save()
        {
            string oldColumn = this.grdViewNhanVien.FocusedColumn.FieldName;
            string newColumn = (oldColumn == this.COLUMN_FIRST ? this.COLUMN_SECOND : this.COLUMN_FIRST);
            this.grdViewNhanVien.FocusedColumn = this.grdViewNhanVien.Columns[newColumn];

            string oldColumnThayDoiCV = this.COLUMN_FIRST_THAYDOICV;
            string newColumnThayDoiCV = this.COLUMN_SECOND_THAYDOICV;
            if (this.grdViewThayDoiChucVu.FocusedColumn != null)
            {
                oldColumnThayDoiCV = this.grdViewThayDoiChucVu.FocusedColumn.FieldName;
                newColumnThayDoiCV = (oldColumnThayDoiCV == this.COLUMN_FIRST_THAYDOICV ? this.COLUMN_SECOND_THAYDOICV : this.COLUMN_FIRST_THAYDOICV);
            }
            this.grdViewThayDoiChucVu.FocusedColumn = this.grdViewThayDoiChucVu.Columns[newColumnThayDoiCV];

            string oldColumnThayDoiLuong = this.COLUMN_FIRST_THAYDOILUONG;
            string newColumnThayDoiLuong = this.COLUMN_SECOND_THAYDOILUONG;
            if (this.grdViewThayDoiLuong.FocusedColumn != null)
            {
                oldColumnThayDoiLuong = this.grdViewThayDoiLuong.FocusedColumn.FieldName;
                newColumnThayDoiLuong = (oldColumnThayDoiLuong == this.COLUMN_FIRST_THAYDOILUONG ? this.COLUMN_SECOND_THAYDOILUONG : this.COLUMN_FIRST_THAYDOILUONG);
            }
            this.grdViewThayDoiLuong.FocusedColumn = this.grdViewThayDoiLuong.Columns[newColumnThayDoiLuong];

            string oldColumnPhuCap = this.COLUMN_FIRST_PHUCAP;
            string newColumnPhuCap = this.COLUMN_SECOND_PHUCAP;
            if (this.grdViewPhuCap.FocusedColumn != null)
            {
                oldColumnPhuCap = this.grdViewPhuCap.FocusedColumn.FieldName;
                newColumnPhuCap = (oldColumnPhuCap == this.COLUMN_FIRST_PHUCAP ? this.COLUMN_SECOND_PHUCAP : this.COLUMN_FIRST_PHUCAP);
            }
            this.grdViewPhuCap.FocusedColumn = this.grdViewPhuCap.Columns[newColumnPhuCap];

            this.bdSource.EndEdit();
            this.nhanVienBOCollection = (NhanVienBOCollection)this.bdSource.DataSource;

            this.bdSourceThayDoiChucVu.EndEdit();
            this.thayDoiChucVuBOCollection = (ThayDoiChucVuBOCollection)this.bdSourceThayDoiChucVu.DataSource;

            this.bdSourceThayDoiLuong.EndEdit();
            this.thayDoiLuongBOCollection = (ThayDoiLuongBOCollection)this.bdSourceThayDoiLuong.DataSource;

            this.bdSourcePhuCap.EndEdit();
            this.khoanPhuCapBOCollection = (KhoanPhuCapBOCollection)this.bdSourcePhuCap.DataSource;

            this.nhanVienBOCollection = this.nhanVienBOCollection.Save();

            int i = 0;
            int length = this.thayDoiChucVuBOCollection.Count;
            int oldID = 0;
            for (i = 0; i < length; i++)
            {
                oldID = this.thayDoiChucVuBOCollection[i].NhanVienID.Value;
                if (this.nhanVienBOCollection.hstID.ContainsKey(oldID))
                    this.thayDoiChucVuBOCollection[i].NhanVienID = (int)this.nhanVienBOCollection.hstID[oldID];
                else //không có chứa trong danh sách mới tức nhân viên đã bị xóa
                    this.thayDoiChucVuBOCollection[i].DELE = true;
            }
            this.thayDoiChucVuBOCollection = this.thayDoiChucVuBOCollection.Save();


            length = this.thayDoiLuongBOCollection.Count;
            for (i = 0; i < length; i++)
            {
                oldID = this.thayDoiLuongBOCollection[i].NhanVienID.Value;
                if (this.nhanVienBOCollection.hstID.ContainsKey(oldID))
                    this.thayDoiLuongBOCollection[i].NhanVienID = (int)this.nhanVienBOCollection.hstID[oldID];
                else //không có chứa trong danh sách mới tức nhân viên đã bị xóa
                    this.thayDoiLuongBOCollection[i].DELE = true;
            }
            this.thayDoiLuongBOCollection = this.thayDoiLuongBOCollection.Save();


            length = this.khoanPhuCapBOCollection.Count;
            for (i = 0; i < length; i++)
            {
                oldID = this.khoanPhuCapBOCollection[i].NhanVienID.Value;
                if (this.nhanVienBOCollection.hstID.ContainsKey(oldID))
                    this.khoanPhuCapBOCollection[i].NhanVienID = (int)this.nhanVienBOCollection.hstID[oldID];
                else //không có chứa trong danh sách mới tức nhân viên đã bị xóa
                    this.khoanPhuCapBOCollection[i].DELE = true;
            }
            this.khoanPhuCapBOCollection = this.khoanPhuCapBOCollection.Save();


            this.bdSource.DataSource = this.nhanVienBOCollection.Clone();
            this.bdSourceThayDoiChucVu.DataSource = this.thayDoiChucVuBOCollection.Clone();
            this.bdSourceThayDoiLuong.DataSource = this.thayDoiLuongBOCollection.Clone();
            this.bdSourcePhuCap.DataSource = this.khoanPhuCapBOCollection.Clone();

            this.grdViewNhanVien.FocusedColumn = this.grdViewNhanVien.Columns[oldColumn];
            this.grdViewThayDoiChucVu.FocusedColumn = this.grdViewThayDoiChucVu.Columns[oldColumnThayDoiCV];
            this.grdViewThayDoiLuong.FocusedColumn = this.grdViewThayDoiLuong.Columns[oldColumnThayDoiLuong];
            this.grdViewPhuCap.FocusedColumn = this.grdViewPhuCap.Columns[oldColumnPhuCap];

            this.formStatus = FormStatus.View;
            SetFormStatus(this.formStatus);
            Session.CloseIndex--;

            this.grdViewNhanVien.CheckLoaded();
            this.grdViewThayDoiChucVu.CheckLoaded();
            this.grdViewThayDoiLuong.CheckLoaded();
            this.grdViewPhuCap.CheckLoaded();

            FilterNhanVien();
        }

        private void Cancel()
        {
            this.formStatus = FormStatus.View;
            SetFormStatus(this.formStatus);
            Session.CloseIndex--;

            this.bdSource.DataSource = this.nhanVienBOCollection.Clone();
            this.bdSourceThayDoiChucVu.DataSource = this.thayDoiChucVuBOCollection.Clone();
            this.bdSourceThayDoiLuong.DataSource = this.thayDoiLuongBOCollection.Clone();
            this.bdSourcePhuCap.DataSource = this.khoanPhuCapBOCollection.Clone();

            this.grdViewNhanVien.CheckLoaded();
            this.grdViewThayDoiChucVu.CheckLoaded();
            this.grdViewThayDoiLuong.CheckLoaded();
            this.grdViewPhuCap.CheckLoaded();

            FilterNhanVien();
        }

        private void SetFormStatus(FormStatus formStatus)
        {
            bool edit = (formStatus != FormStatus.View);
            this.allowCloseForm = !edit;

            int PhongBanID = StaticUtil.GetInt(this.lookUpEditPhongBanID.EditValue, -2);
            bool showGroup = (PhongBanID == -2);
            this.colPhongBanID.GroupIndex = (showGroup ? 0 : -1);
            if (edit)
            {
                this.colDELE.Width = (showGroup ? 25 + 22 : 25);
                this.colSTT0.Width = 25;
            }
            else
            {
                this.colDELE.Width = 25;
                this.colSTT0.Width = (showGroup ? 25 + 22 : 25);
            }

            Utility.SetControlReadOnly(this.tabThongTinCaNhan, !edit);
            Utility.SetControlReadOnly(this.tabCongViec, !edit);
            Utility.SetControlReadOnly(this.pnLuong, !edit);

            MyStyle.SetGridStyle(this.grdViewNhanVien, edit);
            MyStyle.SetGridStyle(this.grdViewThayDoiChucVu, edit);
            MyStyle.SetGridStyle(this.grdViewThayDoiLuong, edit);
            MyStyle.SetGridStyle(this.grdViewPhuCap, edit);

            this.btnPrint.Visible = !edit;
            this.btnEdit.Visible = !edit;
            this.btnClose.Visible = !edit;
            this.btnRefresh.Visible = !edit;

            this.btnSave.Visible = edit;
            this.btnCancel.Visible = edit;

            this.colDELE.Visible = edit;
            this.colSTT0.OptionsColumn.AllowFocus = !edit;
            foreach (GridColumn colNhanVien in this.grdViewNhanVien.Columns)
            {
                if (colNhanVien.Visible)
                    colNhanVien.OptionsColumn.AllowEdit = edit;
            }

            this.colDELE_ThayDoiChucVu.Visible = edit;
            this.colSTT0_ThayDoiChucVu.OptionsColumn.AllowFocus = !edit;
            foreach (GridColumn colThayDoiChucVu in this.grdViewThayDoiChucVu.Columns)
            {
                if (colThayDoiChucVu.Visible)
                    colThayDoiChucVu.OptionsColumn.AllowEdit = edit;
            }

            this.colDELE_ThayDoiLuong.Visible = edit;
            this.colSTT0_ThayDoiLuong.OptionsColumn.AllowFocus = !edit;
            foreach (GridColumn colThayDoiLuong in this.grdViewThayDoiLuong.Columns)
            {
                if (colThayDoiLuong.Visible)
                    colThayDoiLuong.OptionsColumn.AllowEdit = edit;
            }

            this.colDELE_PhuCap.Visible = edit;
            this.colSTT0_PhuCap.OptionsColumn.AllowFocus = !edit;
            foreach (GridColumn colPhuCap in this.grdViewPhuCap.Columns)
            {
                if (colPhuCap.Visible)
                    colPhuCap.OptionsColumn.AllowEdit = edit;
            }


            this.grdViewNhanVien.OptionsView.NewItemRowPosition = (edit ? NewItemRowPosition.Bottom : NewItemRowPosition.None);
            this.grdViewThayDoiChucVu.OptionsView.NewItemRowPosition = (edit ? NewItemRowPosition.Bottom : NewItemRowPosition.None);
            this.grdViewThayDoiLuong.OptionsView.NewItemRowPosition = (edit ? NewItemRowPosition.Bottom : NewItemRowPosition.None);
            this.grdViewPhuCap.OptionsView.NewItemRowPosition = (edit ? NewItemRowPosition.Bottom : NewItemRowPosition.None);

            this.grdViewNhanVien.Focus();

            if (edit)
            {
                string focusColumn = this.grdViewNhanVien.FocusedColumn.FieldName;

                if (string.IsNullOrEmpty(focusColumn))
                    focusColumn = this.COLUMN_FIRST;
                else
                    if (focusColumn == "DELE")
                        focusColumn = this.COLUMN_FIRST;

                if (this.grdViewNhanVien.RowCount == 1)
                    this.grdViewNhanVien.FocusedRowHandle = int.MinValue + 1;

                this.grdViewNhanVien.FocusedColumn = this.grdViewNhanVien.Columns[focusColumn];
                this.grdViewNhanVien.ShowEditor();
            }
        }

        private void InNhanVien()
        {
            int? NhanVienID = StaticUtil.GetRealInt(this.grdViewNhanVien.GetFocusedRowCellValue("NhanVienID"));
            if (NhanVienID != null)
            {
                //lấy vị trí của row được chọn trong nhanvienBOCollection
                int index = this.grdViewNhanVien.GetDataSourceRowIndex(this.grdViewNhanVien.FocusedRowHandle);
                //lấy NhanVienBO
                NhanVienBO nvBO = this.nhanVienBOCollection[index];
                //chuyen NhanVienBO thành RNhanVienBO
                RNhanVienBO nhanVienBO = RNhanVienBO.NewRootRNhanVienBO();
                nhanVienBO.CopyFromNhanVienBO(nvBO);

                object[] arrBOList = new object[] { this.quocTichBOList, this.danTocBOList, this.tonGiaoBOList, this.chuyenMonBOList, this.trinhDoHocVanBOList, this.trinhDoNgoaiNguBOList, this.bangCapBOList, this.trinhDoTinHocBOList };

                Report.rpNhanVien rNhanVien = new TanHungLong.Report.rpNhanVien(arrBOList, nhanVienBO);
                rNhanVien.ShowPreviewDialog();
            }
        }

        private void InTheoPhong()
        {
            int? PhongBanID = StaticUtil.GetRealInt(this.grdViewNhanVien.GetFocusedRowCellValue("PhongBanID"));
            if (PhongBanID != null)
            {
                int length = this.nhanVienBOCollection.Count;
                RNhanVienBOCollection rNhanVienBOCollection = RNhanVienBOCollection.NewRNhanVienBOCollection();
                for (int i = 0; i < length; i++)
                {
                    if (this.nhanVienBOCollection[i].PhongBanID == PhongBanID)
                    {
                        RNhanVienBO nhanVienBO = RNhanVienBOCollection.NewRNhanVienBO();
                        nhanVienBO.CopyFromNhanVienBO(this.nhanVienBOCollection[i]);
                        rNhanVienBOCollection.Add(nhanVienBO);
                    }
                }

                object[] arrBOList = new object[] { this.quocTichBOList, this.danTocBOList, this.tonGiaoBOList, this.chuyenMonBOList, this.trinhDoHocVanBOList, this.trinhDoNgoaiNguBOList, this.bangCapBOList, this.trinhDoTinHocBOList };
                Report.rpDanhSachNhanVien report = new TanHungLong.Report.rpDanhSachNhanVien(arrBOList, rNhanVienBOCollection);
                report.ShowPreviewDialog();
            }
        }

        private void InTatCa()
        {
            int length = this.nhanVienBOCollection.Count;
            RNhanVienBOCollection rNhanVienBOCollection = RNhanVienBOCollection.NewRNhanVienBOCollection();
            for (int i = 0; i < length; i++)
            {
                RNhanVienBO nhanVienBO = RNhanVienBOCollection.NewRNhanVienBO();
                nhanVienBO.CopyFromNhanVienBO(this.nhanVienBOCollection[i]);
                rNhanVienBOCollection.Add(nhanVienBO);
            }

            //
            object[] arrBOList = new object[] { this.quocTichBOList, this.danTocBOList, this.tonGiaoBOList, this.chuyenMonBOList, this.trinhDoHocVanBOList, this.trinhDoNgoaiNguBOList, this.bangCapBOList, this.trinhDoTinHocBOList };
            Report.rpDanhSachNhanVien report = new TanHungLong.Report.rpDanhSachNhanVien(arrBOList, rNhanVienBOCollection);
            report.ShowPreviewDialog();
        }

        private void SetSttNhanVien()
        {
            if (this.formStatus == FormStatus.Edit)
                this.bdSource.EndEdit();

            int length = this.grdViewNhanVien.RowCount;
            int index = 0;
            int stt = 0;
            for (int i = 0; i < length; i++)
            {
                index = this.grdViewNhanVien.GetVisibleRowHandle(i);
                if (index >= 0)
                    this.grdViewNhanVien.SetRowCellValue(index, "STT0", ++stt);
            }

            ((NhanVienBOCollection)this.bdSource.DataSource).SttIndex = stt;
        }

        private void SetSttThayDoiChucVu()
        {
            if (this.formStatus == FormStatus.Edit)
                this.bdSourceThayDoiChucVu.EndEdit();

            int length = this.grdViewThayDoiChucVu.RowCount;
            for (int i = 0; i < length; i++)
                this.grdViewThayDoiChucVu.SetRowCellValue(i, "STT0", i + 1);

            ((ThayDoiChucVuBOCollection)this.bdSourceThayDoiChucVu.DataSource).SttIndex = length;
        }

        private void SetSttThayDoiLuong()
        {
            if (this.formStatus == FormStatus.Edit)
                this.bdSourceThayDoiLuong.EndEdit();

            int length = this.grdViewThayDoiLuong.RowCount;
            for (int i = 0; i < length; i++)
                this.grdViewThayDoiLuong.SetRowCellValue(i, "STT0", i + 1);

            ((ThayDoiLuongBOCollection)this.bdSourceThayDoiLuong.DataSource).SttIndex = length;
        }

        private void SetSttPhuCap()
        {
            if (this.formStatus == FormStatus.Edit)
                this.bdSourcePhuCap.EndEdit();

            int length = this.grdViewPhuCap.RowCount;
            for (int i = 0; i < length; i++)
                this.grdViewPhuCap.SetRowCellValue(i, "STT0", i + 1);

            ((KhoanPhuCapBOCollection)this.bdSourcePhuCap.DataSource).SttIndex = length;
        }
        #endregion function
    }
}